package com.heima.article.listener;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.heima.article.entity.ApArticle;
import com.heima.article.service.IApArticleService;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Service;

@Service
public class UpDownListener {
    @Autowired
    private IApArticleService apArticleService;
    @KafkaListener(topics = "${topic.upDownTopic}")
    public void handleMessage(ConsumerRecord<String,String> consumerRecord)
    {
        String articleId = consumerRecord.key();
        String isAble = consumerRecord.value();
        LambdaUpdateWrapper<ApArticle> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(ApArticle::getId,articleId).set(ApArticle::getIsDown,isAble.equals("true")?false:true);
        apArticleService.update(updateWrapper);
    }
}
